﻿//  菜单显示异常修改tinymce/skins/ui/oxide/skin.min.css:96 .tox-silver-sink的z-index值
//  http://tinymce.ax-z.cn/   中文文档

$(function () {
    layui.define(['jquery'], function (exports) {
        var $ = layui.$;

        var location = (window.location + '').split('/');
        var basePath = location[0] + '//' + location[2];
        var tinymcePath = basePath + '/lib/tinymce';
        var setter = layui.setter || {};

        var response = setter.response || {};

        //var settings = {
        //    base_url: tinymcePath
        //    , images_upload_url: '/rest/doUpload'//图片上传接口
        //    , language: 'zh_CN'
        //    , response: {
        //        statusName: response.statusName || 'code'//返回状态字段
        //        , msgName: response.msgName || 'msg'//返回消息字段
        //        , dataName: response.dataName || 'data'//返回的数据
        //        , statusCode: response.statusCode || {
        //            ok: 0//数据正常
        //        }
        //    }
        //    , success: function (res, succFun, failFun) {//上传完成回调
        //        if (res[this.response.statusName] === this.response.statusCode.ok) {
        //            succFun('/showImage/' + res[this.response.dataName][0]['id']);
        //        } else {
        //            failFun(res[this.response.msgName]);
        //        }
        //    }
        //};

        var t = {};

        t.render = function (option) {

            //var admin = layui.admin || {};

            //option.base_url = option.base_url ? option.base_url : settings.base_url;

            option.language = option.language ? option.language : 'zh_CN';

            option.selector = option.selector ? option.selector : option.elem;

            option.quickbars_selection_toolbar = option.quickbars_selection_toolbar ? option.quickbars_selection_toolbar : 'cut copy | bold italic underline strikethrough';

            option.plugins = option.plugins
                ? option.plugins
                : 'axupimgs print preview importcss searchreplace autolink autosave save directionality visualblocks visualchars fullscreen image link media table charmap hr pagebreak nonbreaking anchor toc insertdatetime advlist lists textpattern noneditable help charmap quickbars emoticons code codesample';
                //: 'axupimgs mycarousel setascoverimg print preview searchreplace autolink fullscreen image link media codesample table charmap hr advlist lists wordcount imagetools indent2em fullscreen';

            option.toolbar = option.toolbar
                ? option.toolbar
                : 'undo redo | bold italic underline strikethrough | fullscreen preview print | link axupimgs media anchor | ltr rtl | fontselect fontsizeselect formatselect | alignleft aligncenter alignright alignjustify | outdent indent |  numlist bullist | forecolor backcolor casechange permanentpen removeformat | pagebreak | charmap emoticons code codesample';
                //: 'undo redo | forecolor backcolor bold italic underline strikethrough superscript subscript removeformat | indent2em alignleft aligncenter alignright alignjustify outdent indent | bullist numlist table fullscreen preview | link axupimgs media | formatselect fontselect fontsizeselect';// |mycarousel setascoverimg';

            option.resize = false;

            option.elementpath = false;

            option.branding = false;

            option.contextmenu_never_use_native = true;

            option.menubar = option.menubar ? option.menubar : false;//'file edit insert format table';

            option.entity_encoding = "raw";

            option.invalid_elements = "scripts";

            option.image_uploadtab = false;

            option.media_live_embeds = true;

            option.toolbar_mode = 'wrap';
            //option.menu = option.menu ? option.menu : {
            //    file: { title: '文件', items: 'newdocument | print preview fullscreen | wordcount' },
            //    edit: { title: '编辑', items: 'undo redo | cut copy paste pastetext selectall | searchreplace' },
            //    format: {
            //        title: '格式',
            //        items: 'bold italic underline strikethrough superscript subscript | formats | forecolor backcolor | removeformat'
            //    },
            //    table: { title: '表格', items: 'inserttable tableprops deletetable | cell row column' },
            //};
                        
            tinymce.init(option);

            t.tinymce = tinymce;

            return tinymce.activeEditor;
        };
        exports('tinymce', t);
    });
});